﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core.Property;

namespace Cofe.Core
{
    public static class LinkFE
    {
        public static IEntryLink[] AddLinks(ICofeSystemInfo src, params ICofeSystemInfo[] entries)
        {
            if (src is IEntryLink)
                throw new ArgumentException("Source cannot be entry link");
           foreach (var entry in entries)
               if (entry is IEntryLink)
                   throw new ArgumentException("Target cannot be entry link");

            List<IEntryLink> retVal = new List<IEntryLink>();
            foreach (var entry in entries)
            {
                
                var linkPH = src.Properties.Behaviors.Invoke<IPropertyHost>(CofeEntryLinkProperties.AddLink,
                new ParameterDic()
                {
                    { "ParseName", entry.ParseName }, 
                    { "Label", entry.Label }
                });

                retVal.Add(CofeServices.EntryConstructor.ConstructEntry<IEntryLink>(linkPH));
            }
            return retVal.ToArray();
        }

        public static IEnumerable<IEntryLink> EnumerateLinks(ICofeSystemInfo src, params ICofeSystemInfo[] entries)
        {
            return from ph in src.Properties.Behaviors.Invoke<IEnumerable<IPropertyHost>>(CofeEntryLinkProperties.GetLinks)
                   select CofeServices.EntryConstructor.ConstructEntry<IEntryLink>(ph);
        }

    }
}
